package fr.ginvest.entity;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "administrateur", uniqueConstraints={ @UniqueConstraint (columnNames={"login"})})
public class Administrateur implements java.io.Serializable {

	private static final long serialVersionUID = 6584298882065808834L;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO) 
	private int id;

	@Basic(optional=false)
	private String login;

	@Basic(optional=false)
	private String motDePasse;
	
	public Administrateur() {}

	public Administrateur(String login, String motDePasse) {
		super();
		this.login = login;
		this.motDePasse = motDePasse;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + id;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Administrateur other = (Administrateur) obj;
		if (id != other.id)
			return false;
		return true;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getMotDePasse() {
		return motDePasse;
	}

	public void setMotDePasse(String motDePasse) {
		this.motDePasse = motDePasse;
	}

	public boolean matchPassword(String pwd) {
        if (pwd == null || "".equals(pwd))
            return false;
        
        if (pwd.equals(motDePasse))
            return true;
        else
        	return false;
    }
}
